//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{
    internal class WebPublishItem : IOfficeXmlSerializable
    {
        private const string xmlName = "webPublishItem";
        private Boolean _autoRepublish;
        private string _destinationFile;
        private string _divId;
        private int _id;
        private string _sourceObject;
        private string _sourceRef;
        private WebSourceType _sourceType;
        private string _title;

        #region IOfficeXmlSerializable Members

        public void ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read(xmlName))
            {
                _id = c.GetUIntegerAsInteger("id");
                _divId = c.GetString("divId");
                _sourceType = c.GetEnum<WebSourceType>("sourceType");
                _sourceRef = c.GetOptionalString("sourceRef");
                _sourceObject = c.GetOptionalString("sourceObject");
                _destinationFile = c.GetString("destinationFile");
                _title = c.GetOptionalString("title");
                _autoRepublish = c.GetOptionalBoolean("autoRepublish", false);
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write(xmlName))
            {
                c.SetUIntegerAsInteger("id", _id);
                c.SetString("divId", _divId);
                c.SetEnum("sourceType", _sourceType);
                c.SetOptionalString("sourceRef", _sourceRef);
                c.SetOptionalString("sourceObject", _sourceObject);
                c.SetString("destinationFile", _destinationFile);
                c.SetOptionalString("title", _title);
                c.SetOptionalBoolean("autoRepublish", _autoRepublish, false);
            }
        }

        #endregion
    }
}